package com.xuecheng.content.api;

import com.xuecheng.model.dto.CoursePreviewDto;
import com.xuecheng.model.po.CoursePublish;
import com.xuecheng.service.CoursePublishPreService;
import com.xuecheng.service.CoursePublishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 小班哥
 * @version 1.0
 * @date 2023/4/16 14:28
 * @description 课程预览接口
 */
@Api(value = "课程预览发布接口",tags = "课程预览发布接口")
@Controller
public class CoursePublishController {

    @Autowired
    private CoursePublishService coursePublishService;

    @Autowired
    private CoursePublishPreService coursePublishPreService;


    @GetMapping("/coursepreview/{courseId}")
    public ModelAndView preview(@PathVariable("courseId") Long courseId){
        //获取课程的基本信息
        CoursePreviewDto coursePreviewDto = coursePublishService.GetCoursePreviewInfo(courseId);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("model",coursePreviewDto);
        modelAndView.setViewName("course_template");
        return modelAndView;
    }



    @PostMapping("/courseaudit/commit/{courseId}")
    @ResponseBody
    public void commitAudit(@PathVariable long courseId){
        long companyId = 1232141425;
        coursePublishPreService.commitAudit(1232141425 , courseId);
    }


    @ApiOperation(value = "课程发布")
    @PostMapping("/coursepublish/{courseId}")
    @ResponseBody
    public void coursepublish(@PathVariable long courseId){
        long companyId = 1232141425;
        coursePublishPreService.PublishCourse(companyId, courseId);
    }

    @ApiOperation( value = "查询课程发布信息")
    @GetMapping(value =  "/r/coursepublish/{courseId}")
    @ResponseBody
    public CoursePublish getCoursepublish(@PathVariable(value = "courseId") long courseId){
        return coursePublishService.getCoursePublish(courseId);
    }

}
